<template>
	<!-- 底部导航 -->
	<view :data-theme="theme">
		<view v-if="bottomNavigationList.length">
			<view class="page-footer" id="target" :style="[isSmallPage?boxStyle:'']">
				<view class="foot-item" v-for="(item,index) in bottomNavigationList" :key="index"
					@click="goRouter(item)">
					<block v-if="item.link.split('?')[0] == activeRouter">
						<image :src="item.checked"></image>
						<view v-if="isSmallPage" class="txtchecked" :style="[checkColor]">{{item.name}}</view>
						<view v-else class="txt">{{item.name}}</view>
					</block>
					<block v-else>
						<image :src="item.unchecked"></image>
						<view class="unchecked" :style="[isSmallPage?fontColor:'']">{{item.name}}</view>
					</block>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters
	} from "vuex"
	import {
		getBottomNavigationApi
	} from '@/api/api.js';
	let app = getApp();
	export default {
		name: 'sfcTabBar',
		props: {
			dataConfig: {
				type: Object,
				default: () => {}
			},
			isSmallPage: {
				type: Boolean,
				default: () => false
			}
		},
		computed: {
			//外部盒子
			boxStyle() {
				if (this.dataConfig) {
					return {
						borderRadius: this.dataConfig.bgStyle.val ? this.dataConfig.bgStyle.val + 'px' : '0',
						background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
						padding: '0' + ' ' + this.dataConfig.lrConfig.val + 'px' + ' ' + 0
					}
				}
			},
			//标签文字颜色
			fontColor() {
				if (this.dataConfig) {
					return {
						color: this.dataConfig.fontColor.color[0].item
					};
				}

			},
			//选中颜色
			checkColor() {
				if (this.dataConfig) {
					return {
						color: this.dataConfig.checkColor.color[0].item
					};
				}
			},
			//上下间距
			spacingStyle() {
				if (this.dataConfig) {
					return {
						marginTop: this.dataConfig.upConfig.val + 'px',
						marginBottom: this.dataConfig.downConfig.val + 'px',
					};
				}

			},
		},
		created() {
			let routes = getCurrentPages(); //获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route //获取当前页面路由
			this.activeRouter = '/' + curRoute;
		},
		mounted() {
			if (this.activeRouter === '/pages/activity/small_page/index') {
				this.bottomNavigationList = this.dataConfig.menuList.list;
			} else {
				this.navigationInfo();
			}
		},
		data() {
			return {
				theme: app.globalData.theme,
				isCustom: '',
				bottomNavigationList: [],
				activeRouter: ''
			}
		},
		methods: {
			navigationInfo() {
				let res = {
					"code": 200,
					"message": null,
					"data": {
						"bottomNavigationList": [{
							"name": "我的",
							"link": "/pages/xyqc/sfc/client/mine",
							"unchecked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/mine.png",
							"checked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/mine-actived.png",
							"id": 1863
						}, {
							"name": "消息",
							"link": "/pages/xyqc/sfc/msg/msg",
							"unchecked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/msg.png",
							"checked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/msg-actived.png",
							"id": 1864
						}, {
							"name": "车主",
							"link": "/pages/xyqc/sfc/driver/driver",
							"unchecked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/driver.png",
							"checked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/driver-actived.png",
							"id": 1865
						}, {
							"name": "顺风车",
							"link": "/pages/xyqc/sfc/client/now",
							"unchecked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/sfc.png",
							"checked": "http://127.0.0.1:8088/crmebimage/manual/sfc-tabbar/sfc-actived.png",
							"id": 1866
						}],
						"isCustom": "1"
					}
				}
				console.log(res.data)
				let data = res.data;
				this.isCustom = data.isCustom; //是否使用自定义导航，1使用，0不使用
				this.$store.commit('BottomNavigationIsCustom', this.isCustom == 1 ? true : false);
				if (data.isCustom == 1) {
					uni.hideTabBar()
					this.bottomNavigationList = data.bottomNavigationList.length > 0 ? data
						.bottomNavigationList
						.reverse() : [];
				} else {
					uni.showTabBar();
				}
			},
			goRouter(item) {
				var pages = getCurrentPages();
				var page = (pages[pages.length - 1]).$page.fullPath;
				console.log('page--', page)
				console.log('link==', item.link)
				if (item.link == page) return
				if (['/pages/xyqc/sfc/client/now', '/pages/xyqc/sfc/driver/driver',
						'/pages/xyqc/sfc/msg/msg', '/pages/xyqc/sfc/client/mine'
					].indexOf(item.link) > -1) {
					uni.redirectTo({
						url: item.link
					})
				} else {
					uni.navigateTo({
						url: item.link
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
	.unchecked {
		color: #333;
		font-size: 24rpx;
	}

	.page-footer {
		position: fixed;
		bottom: 0;
		z-index: 666;
		display: flex;
		align-items: center;
		justify-content: space-around;
		width: 100%;
		height: calc(98rpx+ constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
		height: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
		box-sizing: border-box;
		border-top: solid 1rpx #F3F3F3;
		background-color: #fff;
		box-shadow: 0px 0px 17rpx 1rpx rgba(206, 206, 206, 0.32);
		padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
		padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/

		.foot-item {
			display: flex;
			width: max-content;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			position: relative;

			.count-num {
				position: absolute;
				display: flex;
				justify-content: center;
				align-items: center;
				width: 40rpx;
				height: 40rpx;
				top: 0rpx;
				right: -15rpx;
				color: #fff;
				font-size: 20rpx;
				background-color: #FD502F;
				border-radius: 50%;
				padding: 4rpx;
			}
		}

		.foot-item image {
			height: 50rpx;
			width: 50rpx;
			text-align: center;
			margin: 0 auto;
		}

		.txtchecked {
			font-size: 24rpx;
		}

		.foot-item .txt {
			font-size: 24rpx;
			@include main-color(theme);
		}
	}
</style>